package com.Venue.service.impl;

import com.Venue.entity.Venue;
import com.Venue.mapper.VenueMapper;
import com.Venue.service.VenueService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

@Service
public class VenueServiceImpl implements VenueService {

    private static final Logger log = LoggerFactory.getLogger(VenueServiceImpl.class);
    private static final Random random = new Random();

    @Autowired
    private VenueMapper venueMapper;

    @Override
    public boolean doAddVenueInfo(Venue venue) {
        return venueMapper.doAddVenueInfo(venue) > 0;
    }

    @Override
    public boolean doModifyVenueInfo(Venue venue) {
        return venueMapper.doModifyVenueInfo(venue) > 0;
    }

    @Override
    public boolean doDeleteVenueInfo(Venue venue) {
        return venueMapper.doDeleteVenueInfo(venue) > 0;
    }

    @Override
    public Venue doGetVenueInfo(Venue venue) {
        return venueMapper.doGetVenueInfo(venue);
    }

    @Override
    public List<Venue> doGetVenueInfoList() {
        // 模拟50%的失败率，用于测试熔断
        if (random.nextBoolean()) {
            log.error("模拟服务异常，触发熔断");
            throw new RuntimeException("模拟服务异常，触发熔断");
        }
        return venueMapper.doGetVenueInfoList();
    }

    @Override
    public List<Venue> doQueryVenueInfoList(Venue venue) {
        return venueMapper.doQueryVenueInfoList(venue);
    }
}